import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm, NSpace } from 'naive-ui'

type props = {
  handleEditDict: (row: any) => void
  fetchDelDictData: (id: number) => void
}

export const useDictDataProTable = ({
  handleEditDict,
  fetchDelDictData
}: props) => {
  const columns: ProTableColumn[] = [
    {
      title: '字典标签',
      key: 'label',
      query: {
        type: 'input'
      }
    },
    {
      title: '字典键值',
      key: 'value',
      query: {
        type: 'input'
      }
    },
    {
      title: '字典排序',
      key: 'sortOrder'
    },
    {
      type: 'tag',
      title: '状态',
      key: 'validFlag',
      query: {
        type: 'select'
      },
      dictOptions: [
        {
          value: true,
          label: '正常',
          type: 'primary'
        },
        {
          value: false,
          label: '停用',
          type: 'warning'
        }
      ]
    },
    {
      title: '快捷输入',
      key: 'hotkey'
    },
    {
      title: '备注',
      key: 'remark'
    },
    {
      title: '创建时间',
      key: 'createTime'
    },
    {
      title: '操作',
      key: 'operation',
      render(row) {
        return (
          <>
            {useHasPermi('dictionaryData:edit') && (
              <NButton
                quaternary
                type="primary"
                onClick={() => handleEditDict(row)}
              >
                修改
              </NButton>
            )}
            {useHasPermi('dictionaryData:del') && (
              <NPopconfirm
                onPositiveClick={() => fetchDelDictData(row.id as number)}
              >
                {{
                  trigger: () => (
                    <NButton size="small" type="error" quaternary>
                      删除
                    </NButton>
                  ),
                  default: () => '您确定要删除？'
                }}
              </NPopconfirm>
            )}
          </>
        )
      }
    }
  ]

  return {
    columns
  }
}
